import requests
import time
import random

# 需手动修改这里：填你要访问的单一文章链接
TARGET_URL ="https://chiyang.blog.csdn.net/article/details/155040155?fromshare=blogdetail&sharetype=blogdetail&sharerId=155040155&sharerefer=PC&sharesource=2301_80863610&sharefrom=from_link"

def getHeaders():
    user_agent_list = [
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.3",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.1",
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.",
        "Mozilla/5.0 (iPhone; CPU iPhone OS 16_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Mobile/15E148 Safari/604."
    ]
    return {'User-Agent': random.choice(user_agent_list)}

def access_article():
    '''访问指定单篇文章'''
    try:
        response = requests.get(
            url=TARGET_URL,
            headers=getHeaders(),
            timeout=10
        )
        print(f"访问成功 | 状态码: {response.status_code} | URL: {TARGET_URL}")
        return True
    except Exception as e:
        print(f"访问失败: {str(e)}")
        return False

if __name__ == '__main__':
    # 单次访问模式
    print("正在访问指定文章...")
    for i in range(2000):
        print(f"第 {i+1} 次访问")
        access_article()
        time.sleep(60)   # 间隔5秒

    # 或者：循环访问（取消下方注释，按需修改次数）
     #for i in range(3):  # 示例：访问3次
      #   print(f"第 {i+1} 次访问")
       #  access_article()
        # time.sleep(70)   # 间隔5秒

